/*
 * Copyright (C) 2010 Seapeak.Xu
 *
 * fostmq may be copied only under the terms of the GNU General
 * Public License V3, which may be found in the fostmq source kit.
 *
 * Created on: 2010-8-18
 * Author: Seapeak.Xu
 */

#ifndef FOST_TASKPOOL_H_
#define FOST_TASKPOOL_H_
#ifdef __cplusplus
extern "C"
{
#endif

#include <event.h>
#include <bits/time.h>
#include <stddef.h>
#include <pthread.h>

#include "fost_msg.h"
#include "fost_typedef.h"
#include "fost_event.h"

typedef void (*header_handler_proxy)(void *);
typedef void (*body_handler_proxy)(void *);

typedef struct task_elt_t
{
	int sock;
	int index;
	int use;
	int64 offset;
	pthread_mutex_t locker;
	struct event_base *event_base;
	struct event req_handler;
	struct event resp_handler;
	struct timeval timeout;
	header_t req_header;
	header_t resp_header;
	session_t session_type;
	char req_headerbuff[HEADERLEN + 1];
	char *req_bodybuff;
	char resp_headerbuff[HEADERLEN + 1];
	char *resp_bodybuff;
	struct task_elt_t *next;
	header_handler_proxy header_proxy;
	body_handler_proxy body_proxy;
}task_t;

int taskpool_init(const size_t numb, const size_t timeout,header_handler_proxy header_proxy,body_handler_proxy body_proxy);
	
int taskpool_push(task_t *elt);

task_t *taskpool_pop();

int taskpool_destroy();

#ifdef __cplusplus
}
#endif
#endif /* TASKPOOL_H_ */
